package jp.sourceforge.akjrcp.draw2d;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FocusBorder;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.MouseListener;
import org.eclipse.draw2d.MouseMotionListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout;

public class RoundRectangleButton extends Figure implements MouseMotionListener, MouseListener{
private String label="";
private int roundX=20;
private int roundY=20;
private Font font=new Font(null,"MS Mincho",32,SWT.NONE);

public RoundRectangleButton(){
this.addMouseMotionListener(this);
this.addMouseListener(this);
}
	public void paintFigure(Graphics g){
		g.fillRoundRectangle(this.getClientArea(), roundX, roundY);
		
		g.setFont(font);
		
		TextLayout textLayout=new TextLayout(null);
		textLayout.setText(label);
		textLayout.setWidth(this.getClientArea().width);
		textLayout.setAlignment(SWT.CENTER);
		Rectangle rect=textLayout.getBounds();
		g.drawTextLayout(textLayout,getClientArea().x,getClientArea().y+(this.getClientArea().height-rect.height)/2);
		
	}
	public Font getFont() {
		return font;
	}
	public void setFont(Font font) {
		this.font = font;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public int getRoundX() {
		return roundX;
	}
	public void setRoundX(int roundX) {
		this.roundX = roundX;
	}
	public int getRoundY() {
		return roundY;
	}
	public void setRoundY(int roundY) {
		this.roundY = roundY;
	}
	
	public void mouseDragged(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	public void mouseEntered(MouseEvent me) {
		this.setBorder(new FocusBorder());
		this.repaint();
	}
	public void mouseExited(MouseEvent me) {
		this.setBorder(null);
		this.repaint();
	}
	public void mouseHover(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	public void mouseMoved(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	public void mouseDoubleClicked(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	public void mousePressed(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	public void mouseReleased(MouseEvent me) {
		clickButton();
	}
	
	protected void clickButton() {
		//do nothing here.
	}
}
